Skip to content

Add ability to load development-only environment variables#22

Merged
yCodeTech merged 6 commits intomasterfrom
feat/dev-env-variables
Feb 6, 2026
Merged

Add ability to load development-only environment variables#22
yCodeTech merged 6 commits intomasterfrom
feat/dev-env-variables

Conversation

@yCodeTech
Copy link
Owner

@yCodeTech yCodeTech commented Feb 4, 2026

This pull request introduces support for loading and validating development environment variables from a .env file, allowing for easier local development and testing. The most important changes are grouped below by theme:

Development environment support:

  • Added a new addDevEnvVariables function in src/utils.ts that loads environment variables from a local .env file and validates them, specifically focusing on DEV_USER_EXTENSIONS_PATH.
  • Updated src/extension.ts to call addDevEnvVariables during extension startup, ensuring development environment variables are loaded before initializing extension data.

Environment variable validation:

  • Implemented validation logic in src/utils.ts to sanitize DEV_USER_EXTENSIONS_PATH, removing it from the environment and logging errors if the path is invalid or inaccessible.

Extension discovery paths:

  • Modified ExtensionData.setExtensionDiscoveryPaths in src/extensionData.ts to use the DEV_USER_EXTENSIONS_PATH environment variable if present, allowing custom user extension paths during development.

Dependency updates:

  • Added path module import in src/utils.ts to support path resolution and validation for environment variables.

~ Summary generated by Copilot

- Added `addDevEnvVariables` util function to allow the extension to load the local `.env` file from the project root if it exists, using Node's `loadEnvFile` API, and load the environment variables into `process.env`. The `.env` file will only exist on the development machine and is crucial to properly test the extension in vscode's extension testing environment.

This fixes the ability to mistakenly commit the dev testing path to git. As seen in commit be9d972 and removed in commit 9ff0857 of PR #20. With the .env file, this will never happen again.

- Added the `addDevEnvVariables` function call to the top of the `extension.ts` file so it is the first thing it does and the env variables will be available in all files in development.

- Added the usage of the `DEV_USER_EXTENSIONS_PATH` env variable to `ExtensionData::setExtensionDiscoveryPaths` method. So that when its available to use, it will override the `userExtensionsPath` variable with the path set in the env variable.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds developer-focused configuration hooks by loading local .env variables and allowing an environment-variable override for the user extensions discovery path.

Changes:

  • Introduces addDevEnvVariables() to load a local .env file at startup.
  • Allows overriding the computed userExtensionsPath via DEV_USER_EXTENSIONS_PATH.
  • Ignores .env in git to avoid committing local secrets.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/utils.ts Adds .env loading helper using process.loadEnvFile.
src/extension.ts Invokes .env loading during extension module initialization.
src/extensionData.ts Uses DEV_USER_EXTENSIONS_PATH to override extension discovery path.
.gitignore Adds .env to ignored files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Feb 4, 2026

@yCodeTech I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you.

yCodeTech and others added 4 commits February 6, 2026 02:54
A duplicate output channel is sometimes created when logging. Possibly because it is setup after `ExtensionData`, and any logs from that class or earlier in the run, will create additional channels, without realising there's one already created.

- Fixed by moving `logger.setupOutputChannel` call up the run order to before the `addDevEnvVariables` call in the extension file. This should help prevent duplicate channels, and log to only one channel.
- Added `validateDevEnvVariables` util function to validate and sanitize the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function call to `addDevEnvVariables` util function.

This function is based on the code Copilot created in PR #23, but with significant improvement.
- Added `validateDevEnvVariables` util function to validate and sanitize
the `DEV_USER_EXTENSIONS_PATH` env variable value. Added it's function
call to `addDevEnvVariables` util function.

This function is based on the code Copilot created in PR #23, but with
significant improvement.
- Fixed `errorMsg` variable in `validateDevEnvVariables` util function to be initialised as an empty string. This avoids errors when trying to call `.length` on it later.
@yCodeTech yCodeTech added the enhancement New feature or quality of life enhancement label Feb 6, 2026
@yCodeTech yCodeTech merged commit a3056b5 into master Feb 6, 2026
1 check passed
@yCodeTech yCodeTech deleted the feat/dev-env-variables branch February 6, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or quality of life enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants